package com.demo.aidroid;

import android.app.Application;
import android.content.Intent;
import android.util.Log;

import com.demo.aidroid.services.IflyEngineService;
import com.demo.aidroid.services.ScreenLockService;
import com.iflytek.cloud.SpeechUtility;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;

/**
 * Created by kevinLiao on 2017/6/29.
 */

public class App extends Application {
    private static String webSocketServer;

    public static App instance;

    public static String getWebSocketServer() {
        return webSocketServer;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        SpeechUtility.createUtility(App.this, "force_login=true,appid=" + getString(R.string.app_id));
        getGPRSLocalIpAddress();
        webSocketServer = getString(R.string.ws_server);
        instance = this;
        startService(new Intent(this, ScreenLockService.class));
        startService(new Intent(this, IflyEngineService.class));
    }

    public static App getInstances() {
        return instance;
    }

    private void getGPRSLocalIpAddress() {
        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface
                    .getNetworkInterfaces(); en.hasMoreElements(); ) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = intf
                        .getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress()) {
                        Log.d("Service", inetAddress.getHostAddress());
                    }
                }
            }
        } catch (Exception ex) {
            Log.e("Service", "WifiPreference IpAddress", ex);
        }
    }



}
